.PHONY  =all clean veryclean
FSROUTE  =fsroute.fs
FSORDER	=fsorder.fs
FSBILL  =fsbill.fs
FSCONF  =fsconf.fs
FSMONITOR  =fsmonitor.fs

DEBUG=
#DEBUG= -D_DEBUG -pg
ESL = /root/fs/freeswitch/libs/esl/

OPT =-g -O0 -Wall $(DEBUG) -D APR_DECLARE_STATIC -D APU_DECLARE_STATIC -D LOG4CXX_STATIC -D ESL_DECLARE_STATIC
INCLUDE = $(shell  /usr/local/apr/bin/apu-1-config --includes) -I$(ESL)/src/include $(ORACLE_INCLUDE)
LDFLAGS = -L/usr/local/lib -L/usr/local/apr/lib -L/root/fs/freeswitch/libs/esl/  -L/usr/lib64/mysql -Wl,-Bstatic -lmysqlcppconn-static -llog4cxx -laprutil-1 -lapr-1 -lexpat -lesl -Wl,-Bdynamic -lmysqlclient_r -lpthread 
COMMONSOURCES  =common/dbs.h common/dbs.cpp common/inifile.h common/trim.h common/daemon.cpp 

FSROUTESRC =fsroute/fsroute.cpp  $(COMMONSOURCES)
FSORDERSRC =fsorder/fsorder.cpp fsorder/orderdb.cpp fsorder/fsorder.h $(COMMONSOURCES)
FSBILLSRC = fsbill/fsbill.cpp $(COMMONSOURCES)
FSCONFSRC = fsconference/fsconference.cpp fsconference/conferencedb.cpp fsconference/fsconference.h $(COMMONSOURCES)
FSMONITORSRC = fsmonitor/fsmonitor.cpp $(COMMONSOURCES)

CFLAGS  +=$(OPT) $(INCLUDE)
CC    =gcc
CXX   =g++
CXXFLAGS    +=$(OPT) $(INCLUDE) 

OBJS  = $(addsuffix .o, $(basename $(filter %.c %.cpp , $(FSROUTESRC) $(FSORDERSRC) $(FSBILLSRC) $(FSCONFSRC) $(FSMONITORSRC))))

all : $(FSROUTE) $(FSORDER) $(FSBILL) $(FSCONF) $(FSMONITOR)

$(FSROUTE):$(addsuffix .o, $(basename $(filter %.c %.cpp ,$(FSROUTESRC))))
	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@


$(FSORDER) :$(addsuffix .o, $(basename $(filter %.c %.cpp ,$(FSORDERSRC))))
	$(CXX)  $(CXXFLAGS) $^ $(LDFLAGS)  -o $@

$(FSBILL) :$(addsuffix .o, $(basename $(filter %.c %.cpp ,$(FSBILLSRC))))
	$(CXX)  $(CXXFLAGS) $^ $(LDFLAGS)  -o $@

$(FSCONF) :$(addsuffix .o, $(basename $(filter %.c %.cpp ,$(FSCONFSRC))))
	$(CXX)  $(CXXFLAGS) $^ $(LDFLAGS)  -o $@

$(FSMONITOR) :$(addsuffix .o, $(basename $(filter %.c %.cpp ,$(FSMONITORSRC))))
	$(CXX)  $(CXXFLAGS) $^ $(LDFLAGS)  -o $@

clean:
	-rm -rf $(OBJS) *.o *.d core* *.bak $(FSROUTE) $(FSORDER) $(FSBILL) $(FSCONF) $(FSMONITOR)
